############################################################
# Did people share any messages?
# 
# Author: 
# Soubhik Barari
# 
# Environment:
# - must use R 3.6
# 
# Input:
# - 00-read_clean_data.R
############################################################

source("00-read_clean_data.R")

#----------------------------------------------------------
# What predicts message sharing?
#----------------------------------------------------------

qcols <- colnames(responses_df)[grepl("Q62", colnames(responses_df))]
nshared <- apply(responses_df[,qcols], 1, function(row) sum(row != ""))
responses_df$nshared <- nshared
responses_df$did_share <- ifelse(responses_df$nshared >= 1, 1, 0)
responses_df$nshared[responses_df$nshared > 5] <- 5
data.frame(x=as.factor(responses_df$nshared)) %>% 
	ggplot(aes(x=x)) + 
	geom_histogram(stat="count") +
	xlab("number of emails/phone numbers shared") + 
	ylab("number of respondents") +
	theme_bw()
ggsave("share_hist.pdf", width=6, height=3)
ggsave("share_hist.png", width=6, height=3)

cat("\noverall mean # of contacts shared:\n")
cat(mean(nshared))
# 0.5272306

nshared.men <- apply(responses_df[responses_df$gender == "Male",qcols], 1, function(row) sum(row != ""))
cat("\nmean # of contacts shared for men:\n")
cat(mean(nshared.men))
# 0.5498489

nshared.women <- apply(responses_df[responses_df$gender == "Female",qcols], 1, function(row) sum(row != ""))
cat("\nmean # of contacts shared for women:\n")
cat(mean(nshared.women))
# 0.5414925

##################################################################
########### WHAT DID PEOPLE THINK WAS THE MOST EFFECTIVE MSG?
##################################################################

t <- table(responses_df$Q35[responses_df$Q35 != ""])

effmsg <- data.frame(
    message=c("externalities (default)", "externalities + naming", "fun", "doctors", "majority"),
    num = t
)

effmsg <- effmsg %>% arrange(-num.Freq)
effmsg$message <- factor(effmsg$message, levels=rev(effmsg$message))
p <- ggplot(effmsg, aes(x=message, y=num.Freq)) +
    geom_bar(stat="identity") +
    coord_flip() + ylab(sprintf("# (n=%d)", nrow(responses_df))) +
    theme_bw()
p
ggsave("share_message.pdf", width=5, height=3)
ggsave("share_message.png", width=5, height=3)

##################################################################
########### SO WHO *DID* SHARE MESSAGES?
##################################################################
responses_df$anxiety_group <- ifelse(
    responses_df$anxiety_index < 0.3, "low",
    ifelse(
        responses_df$anxiety_index > 0.3 & responses_df$anxiety_index < 0.6, "med",
        ifelse(
            responses_df$anxiety_index > 0.6,
            "hi", NA
        )
    )
)

responses_df$think_effec <- ifelse(responses_df$perceivedeffectivnes %in% c("Effective", "Very effective"), 1, 0)
responses_df$think_publ_extreme <- ifelse(responses_df$Q23 %in% c("The reaction is much too extreme", "The reaction is somewhat too extreme"), 1, 0)
responses_df$think_govt_extreme <- ifelse(responses_df$perceivedreaction %in% c("The reaction is much too extreme", "The reaction is somewhat too extreme"), 1, 0)
responses_df$trust_govt <- ifelse(responses_df$Q36 %in% c("Strongly distrust", "Distrust"), 1, 0)
responses_df$factu_govt <- ifelse(responses_df$Q37 %in% c("Very untruthful", "Somewhat untruthful"), 1, 0)

responses_df$anxiety_group <- factor(responses_df$anxiety_group, levels=c("low", "med", "hi"))

m1 <- lm(nshared ~ trust_govt + factu_govt + think_govt_extreme + think_publ_extreme + think_effec + age_group + gender + health + treatment + anxiety_group + past_healthy_behavior_binary, data=responses_df)
summary(m1) 
##no one in particular
##... negative effect for those receiving reflection treatment (1)
##positive effect for those who personally think social distancing is effective

m1 <- glm(did_share ~ trust_govt + factu_govt + think_govt_extreme + think_publ_extreme + think_effec + age_group + gender + health + treatment + anxiety_group + past_healthy_behavior_binary, data=responses_df, family=binomial())
summary(m1) 
##no one in particular
##... negative effect for those receiving reflection treatment (1)
##positive effect for those who personally think social distancing is effective

m2 <- glm.nb(nshared ~ trust_govt + factu_govt + think_govt_extreme + think_publ_extreme + think_effec + age_group + gender + health + treatment + anxiety_group + past_healthy_behavior_binary, data=responses_df, link="log")
summary(m2)
##no one in particular
##... negative effect for those receiving reflection treatment (1)
##positive effect for those who personally think social distancing is effective

library(pscl)
m3 <- pscl::zeroinfl(nshared ~ trust_govt + factu_govt + think_govt_extreme + think_publ_extreme + think_effec + age_group + gender + health + treatment + anxiety_group + past_healthy_behavior_binary, data=responses_df, dist="poisson")
summary(m3)
##no one in particular
##positive effect for those who personally think social distancing is effective
